<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020.06.22
  Time: 上午 11:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<html>
<head>
    <title>修改密码</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/static/layui/css/layui.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 50px;">
    <legend>修改密码</legend>
</fieldset>
<form class="layui-form">
    <div class="layui-form-item">
        <label class="layui-form-label">原密码</label>
        <div class="layui-input-inline">
            <input lay-verify="required" type="password" name="pa" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">修改密码</label>
        <div class="layui-input-inline">
            <input id="p1" lay-verify="required|pass" type="password" name="pa1" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">确认密码</label>
        <div class="layui-input-inline">
            <input id="p2" lay-verify="required|pass" type="password" name="pa2" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-inline" style="position: absolute;left: 800px;z-index: 10">
        <div class="layui-input-inline">
            <button class="layui-btn" lay-filter="query"  lay-submit>修改</button>
        </div>
    </div>
</form>

<script src="${pageContext.request.contextPath}/static/layui/layui.js"></script>
<script>
layui.use(['form','jquery','layer'], function(){
var form = layui.form;
var $ = layui.$;
var layer = layui.layer;

    form.verify({
        pass: [
            /^[\S]{6,16}$/
            ,'密码必须6到16位，且不能出现空格'
        ]

    });

    form.on('submit(query)', function(data){
        console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
        console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
        console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
        if (data.field.pa1===data.field.pa2) {
            $.ajax({
            url:"${pageContext.request.contextPath}/users/password",
            type:"post",
            data:data.field,
            dataType: "json",
            success:function (result) {
            if (result.code==0){
            layer.msg("修改成功")
            window.location.reload();
            }else{
                layer.msg("密码错误")
            }
            }
            })
        }else {
            layer.msg("两次密码不一致");
        }

        return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
    });



});
</script>
</body>
</html>
